#include <iostream>
#include <vector>
#include <map>
#include <algorithm>

bool cmp(std::pair<std::string, int> a, std::pair<std::string, int> b)
{
    std::string a_id = a.first.substr(0, 5);
    std::string b_id = b.first.substr(0, 5);

    if (a_id < b_id)
    {
        return true;
    }
    else if (a_id > b_id)
    {
        return false;
    }
    else
    {
        if (a.second > b.second)
        {
            return true;
        }
        else if (a.second < b.second)
        {
            return false;
        }
        else
        {
            return a.first > b.first;
        }
    }
}

void sparseStr(std::string str, std::map<std::string, std::vector<int>> &score_map)
{
    int i = 0;
    while (i < str.size())
    {
        std::string id;
        while (i < str.size() && str[i] != ',')
        {
            id.push_back(str[i]);
            i++;
        }
        i++;

        std::string score;
        while (i < str.size() && str[i] != ';')
        {
            score.push_back(str[i]);
            i++;
        }
        i++;
        score_map[id].push_back(std::stoi(score));
    }
}

int main()
{
    std::map<std::string, std::vector<int>> score_map;

    std::string tmp_str1;
    std::cin >> tmp_str1;
    sparseStr(tmp_str1, score_map);

    std::string tmp_str2;
    std::cin >> tmp_str2;
    sparseStr(tmp_str2, score_map);

    std::vector<std::pair<std::string, int>>
        score_vec;
    for (auto it = score_map.begin(); it != score_map.end(); ++it)
    {
        if (it->second.size() == 2)
        {
            score_vec.push_back({it->first, it->second[0] + it->second[1]});
        }
    }

    if (score_vec.empty())
    {
        std::cout << "NULL" << std::endl;
    }
    else
    {
        std::sort(score_vec.begin(), score_vec.end(), cmp);

        std::string class_id = score_vec[0].first.substr(0, 5);
        std::cout << class_id << std::endl;
        std::cout << score_vec[0].first;
        int i = 1;
        while (i < score_vec.size())
        {
            std::string tmp_id = score_vec[i].first.substr(0, 5);
            while (i < score_vec.size() && tmp_id == class_id)
            {
                std::cout << "," << score_vec[0].first;
                i++;
                tmp_id = score_vec[i].first.substr(0, 5);
            }

            if (tmp_id != class_id)
            {
                std::cout << std::endl;
                class_id = tmp_id;
                std::cout << class_id << std::endl;
                std::cout << score_vec[i].first;
                i++;
            }
        }
    }
    std::cout << std::endl;

    return 0;
}